package com.huaxin.common.Entity;

import android.os.Parcel;
import android.os.Parcelable;
import android.view.View;
import android.widget.TextView;

import com.huaxin.common.R;

import java.util.List;


/**
 * Created by Administrator on 2016/9/6.
 * {"address":"地址5","areaName":"古田","contactPerson":"A先生","contactPhone":"110","deviceList":[
 * {"deviceCode":"5","deviceName":"hx-300","deviceState":1,"deviceType":"常规活性污泥法",
 * "readCycle":"2323","sendCycle":"4442","snCode":"4444"},{"deviceCode":"14","deviceName":"泵机"}],
 * "imgs":[],"lat":30.567886,"lng":114.231213,"orgName":"城市排水(武汉)有限公司","checkState":1,
 * "stationName":"测试站点5","processCapacity":"500","servicePeople":300,""stationState":1}
 */
public class StationDTO extends BaseDTO implements Parcelable {

    int stationState;
    String stationCode;
    String stationName;
    String orgName;
    String address;
    String areaName;
    String contactPerson;
    String contactPhone;
    double lng;
    double lat;
    String stationImg;
    String processCapacity;
    int servicePeople;
    List<Device> deviceList;
    int type;//站点分栏显示 1表是厂 2站点

    protected StationDTO(Parcel in) {
        stationState = in.readInt();
        stationCode = in.readString();
        stationName = in.readString();
        orgName = in.readString();
        address = in.readString();
        areaName = in.readString();
        contactPerson = in.readString();
        contactPhone = in.readString();
        lng = in.readDouble();
        lat = in.readDouble();
        stationImg = in.readString();
        processCapacity = in.readString();
        servicePeople = in.readInt();
        deviceList = in.createTypedArrayList(Device.CREATOR);
        type = in.readInt();
    }

    public static final Creator<StationDTO> CREATOR = new Creator<StationDTO>() {
        @Override
        public StationDTO createFromParcel(Parcel in) {
            return new StationDTO(in);
        }

        @Override
        public StationDTO[] newArray(int size) {
            return new StationDTO[size];
        }
    };

    @Override
    public String toString() {
        return "StationDTO{" +
                "stationState=" + stationState +
                ", stationCode='" + stationCode + '\'' +
                ", stationName='" + stationName + '\'' +
                ", orgName='" + orgName + '\'' +
                ", address='" + address + '\'' +
                ", areaName='" + areaName + '\'' +
                ", contactPerson='" + contactPerson + '\'' +
                ", contactPhone='" + contactPhone + '\'' +
                ", lng=" + lng +
                ", lat=" + lat +
                ", stationImg='" + stationImg + '\'' +
                ", processCapacity='" + processCapacity + '\'' +
                ", servicePeople=" + servicePeople +
                ", deviceList=" + deviceList +
                ", type=" + type +
                '}';
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getServicePeople() {
        return servicePeople;
    }

    public String getProcessCapacity() {
        return processCapacity;
    }

    public String getStationImg() {
        return stationImg;
    }

    public int getStationState() {
        return stationState;
    }

    public String getStationCode() {
        return stationCode;
    }

    public String getStationName() {
        return stationName;
    }

    public String getOrgName() {
        return orgName;
    }

    public String getAddress() {
        return address;
    }

    public String getAreaName() {
        return areaName;
    }

    public String getContactPerson() {
        return contactPerson;
    }

    public String getContactPhone() {
        return contactPhone;
    }

    public double getLng() {
        return lng;
    }

    public double getLat() {
        return lat;
    }

    public void setStationCode(String stationCode) {
        this.stationCode = stationCode;
    }

    public List<Device> getDeviceList() {
        return deviceList;
    }

    public static void setStateText(TextView textView, String state) {
        setStateText(textView, Integer.parseInt(state));
    }

    public static void setStateText(TextView textView, int state) {
        //站点状态 0:正常，1：通讯超时，2、故障，3、待初始化
        textView.setVisibility(View.VISIBLE);
        switch (state) {
            case 0:
                textView.setText("正常");
                textView.setTextColor(textView.getResources().getColor(R.color.state_blue));
                textView.setBackgroundResource(R.drawable.bg_normal);
                break;
            case 1:
                textView.setText("超时");
                textView.setTextColor(textView.getResources().getColor(R.color.state_orange));
                textView.setBackgroundResource(R.drawable.bg_bug);
                break;
            case 2:
                textView.setText("故障");
                textView.setTextColor(textView.getResources().getColor(R.color.state_red));
                textView.setBackgroundResource(R.drawable.bg_bug);
                break;
            case 3:
                textView.setText("待初始化");
                textView.setTextColor(textView.getResources().getColor(R.color.state_gray));
                textView.setBackgroundResource(R.drawable.bg_bug);
                break;
            default:
                textView.setVisibility(View.GONE);
                break;
        }
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeInt(stationState);
        parcel.writeString(stationCode);
        parcel.writeString(stationName);
        parcel.writeString(orgName);
        parcel.writeString(address);
        parcel.writeString(areaName);
        parcel.writeString(contactPerson);
        parcel.writeString(contactPhone);
        parcel.writeDouble(lng);
        parcel.writeDouble(lat);
        parcel.writeString(stationImg);
        parcel.writeString(processCapacity);
        parcel.writeInt(servicePeople);
        parcel.writeTypedList(deviceList);
        parcel.writeInt(type);
    }
}
